package com.UnionPayCenter.vastchain.impl;

import com.UnionPayCenter.vastchain.VastChainClient;
import com.UnionPayCenter.vastchain.VastChainService;
import com.UnionPayCenter.vastchain.request.ParentMerchantRequest;
import com.UnionPayCenter.vastchain.request.PaymentRequest;
import com.UnionPayCenter.vastchain.request.SubMerchantRequest;
import com.UnionPayCenter.vastchain.response.ParentMerchantResponse;
import com.UnionPayCenter.vastchain.response.SubMerchantResponse;
import com.UnionPayCenter.vastchain.response.VastChainBaseResponse;
import com.UnionPayCenter.vastchain.response.params.ParentMerchantResponseParams;
import com.UnionPayCenter.vastchain.response.params.SubMerchantResponseParams;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Service;

import javax.sound.midi.Soundbank;
import java.util.Objects;


/**
 * @author noah
 * @since 1.0.0, 2019/08/20
 */
@Service
public class VastChainServiceImpl implements VastChainService {

    @Override
    public ParentMerchantResponseParams creatParentMerchant(ParentMerchantRequest request) {
        String url = "/merchant/";
        VastChainClient vastChainClient = new VastChainClient();
        ParentMerchantResponse response = vastChainClient.doPost(url, JSONObject.toJSONString(request),null,ParentMerchantResponse.class);
        if(Objects.nonNull(response) && "success".equals(response.getStatus())){
            return response.getData();
        }
        return null;
    }

    @Override
    public SubMerchantResponseParams creatSubMerchant(SubMerchantRequest request) {
        String url = "/merchant/";
        VastChainClient vastChainClient = new VastChainClient();
        SubMerchantResponse response = vastChainClient.doPost(url, JSONObject.toJSONString(request),null, SubMerchantResponse.class);
        if(Objects.nonNull(response) && "success".equals(response.getStatus())){
            return response.getData();
        }
        return null;
    }

    @Override
    public boolean modifyPaymentParams(PaymentRequest request) {
        String url = "/merchant/paymentParams";
        VastChainClient vastChainClient = new VastChainClient();
        VastChainBaseResponse response = vastChainClient.doPut(url, JSONObject.toJSONString(request),null, VastChainBaseResponse.class);
        if(Objects.nonNull(response) && "success".equals(response.getStatus())){
            return true;
        }
        return false;
    }
}
